const Net = require('../../../Net')
Page({
  data: {
    autoplay: true,
    interval: 5000,
    previous_margin: '60px',
    next_margin: '60px',
    currentItemId: 0,
    showImage: ''
  },
  onLoad: function (options) {},
  onPageInfo() {
    Net.link('v1/refereeShare', {}, function (res) {
      Net.data({
        info: res.data.data
      })
    }, 'GET')
  },
  hid() {
    Net.data({
      showImage: ''
    })
  },
  swiperChange: function (e) {
    var currentItemId = e.detail.currentItemId;
    this.setData({
      currentItemId: currentItemId
    })
  },
  yearSwiperChange(e) {
    let current = e.detail.current;
    let that = this;
    that.setData({
      swiperCurrent: current,
    })
  },
  onReady: function () {},
  onShow: function () {
    var _this = this
    _this.onPageInfo()
  },
  onShowMdal(e) {
    if (e.currentTarget.id == 0) {
      var list = Net.data('info'),
        index = Net.data('currentItemId'),
        id = list.list[index].index
      Net.link('v1/refereeShare', {
        index: id
      }, function (res) {
        wx.getImageInfo({
          src: res.data.data.image,
          success(res) {
            console.log(res.path)
            wx.saveImageToPhotosAlbum({
              filePath: res.path,
              success(res) {
                wx.showModal({
                  title: '温馨提示',
                  content: '保存相册成功',
                  showCancel: false
                })
              }
            })
          }
        })
      }, 'GET')
    }
  },
  butSave() {
    wx.getImageInfo({
      src: Net.data('showImage'),
      success(res) {
        console.log(res.path)
        wx.saveImageToPhotosAlbum({
          filePath: res.path,
          success(res) {
            wx.showModal({
              title: '温馨提示',
              content: '保存相册成功',
              showCancel: false,
              success(res) {
                Net.data({
                  showImage: ''
                })
              }
            })
          }
        })
      }
    })
  },
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function (res) {
    if (res.from != "menu") {
      return {
        title:wx.getStorageSync('member').member_pdd_oauth.nickname + '邀请您加入喜赠',
        path: '/pages/onNewPages/invitation/invitation?q=' + wx.getStorageSync('member').number,
        imageUrl: 'https://huixuangou.oss-cn-beijing.aliyuncs.com/wechat/Xz_MiNi_image/008181811.jpg'
      }
    } else {
      console.log('跳转首页分享')
      return {
        title: '喜赠小程序',
        path: '/tabbarPage/index/index'
      }
    }
  }
})